<?php
declare(strict_types=1);

namespace LowCode\Naive;

use LowCode\Naive;
use LowCode\Traits\Events\HasOnClose;
use LowCode\Traits\Props\HasBordered;
use LowCode\Traits\Props\HasClosable;
use LowCode\Traits\Props\HasTitle;
use LowCode\Traits\Props\HasType;
use LowCode\Traits\Slots\HasSlotHeader;
use LowCode\Traits\Slots\HasSlotIcon;

/**
 * Alert组件
 * @method static static make(mixed $children = null) Alert组件
 */
class Alert extends Naive
{
    use HasBordered, HasClosable, HasTitle, HasType;

    use HasSlotHeader, HasSlotIcon;

    use HasOnClose;

    public function __construct(mixed $children = null)
    {
        parent::__construct();
        $this->children($children);
    }

    /**
     * 类型
     * @param string $type 'default' | 'info' | 'success' | 'warning' | 'error'
     * @return $this
     */
    public function type(string $type = 'default' | 'info' | 'success' | 'warning' | 'error'): static
    {
        return $this->prop('type',$type);
    }

    /**
     * 默认标签类型
     * @return $this
     */
    public function default(): static
    {
        return $this->type('default');
    }

    /**
     * default
     * @return $this
     */
    public function primary(): static
    {
        return $this->default();
    }

    /**
     * alert 是否展示 icon
     * @param bool|string $bool
     * @return $this
     */
    public function showIcon(bool|string $bool = true): static
    {
        return $this->prop('show-icon', $bool);
    }

    /**
     * alert 消失时执行的回调函数
     * @param string $event 函数 () => {}
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onAfterLeave(string $event = "()=>{  }", string $id = null, array $modifiers = []): static
    {
        return $this->event("afterLeave",jsFn($event, $id), $modifiers);
    }


}
